<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form 
        action="/upload" 
        method="post"
        enctype="multipart/form-data"
        >
        <input type="file" id="file" name="img">
        <img src="" alt="">
        <input type="submit">
    </form>
    <script>
        var file = document.querySelector("#file");
        var oImg = document.querySelector("img");
        file.onchange = function(){
           
            console.log(this.files);
            let fd = new FileReader();

            fd.readAsDataURL(this.files[0]);

            fd.onload = function(){
                console.log(this.result);
                oImg.src=this.result;
            }

        }
    </script>
</body>
</html>